<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <canvas
      id="canvas"
      style="border: 1px solid red; background-color: orange"
    ></canvas>
    <script>
      const canvas = document.getElementById("canvas");
      const ctx = canvas.getContext("2d");

      // rect 方法仅定义，需要使用 fill/stroke 绘制
      ctx.rect(0, 0, 100, 150);
      ctx.fillStyle = "red";
      ctx.fill();

      ctx.fillStyle = "green";
      ctx.fillRect(100, 0, 100, 150);

      ctx.strokeStyle = "blue";
      ctx.strokeRect(200, 0, 100, 150);

      // clearRect (清除后的颜色为透明色)
      ctx.clearRect(25, 50, 50, 50);
    </script>
  </body>
</html>
